<?php namespace Admin\Controller; 

use Admin\Model\Cat;

/**
 * 商品栏目管理
 * @author 向军 <2300071698@qq.com>
 */
class CatController extends AuthController{
	//商品属性模型对象
	protected $db;
	//构造函数
	public function __init()
	{
		$this->db = new Cat;
	}

    //列表
	public function index(){
		$data = $this->db->getAll();
		View::with('data',$data);
		View::make();
	}

	//添加
	public function add(){
		if(IS_POST)
		{
			if($this->db->store())
			{
				View::success('添加成功',U('index'));
			}
			else
			{
				View::error($this->db->getError());
			}
		}
		else
		{
			$cat = $this->db->getAll();
			//分配商品类型
			View::with('goodsType',Db::table('shop_type')->get());
			View::with('cat',$cat);
			View::make();
		}
	}

	//修改
	public function edit(){
		if(IS_POST)
		{
			if($this->db->edit())
			{
				View::success('操作成功',U('index'));
			}
			else
			{
				View::error($this->db->getError());
			}
		}
		else
		{
			$field = $this->db->one($_GET['cat_id']);
			$cat = $this->db->getAll();
			View::with('field',$field)->with('cat',$cat);

			//分配商品类型
			View::with('goodsType',Db::table('shop_type')->get());
			View::make();
		}
	}
}















